<template>
  <p-drawer
    placement="right"
    :closable="false"
    width="calc(100vw - 200px)"
    :visible="visible"
    :mask-closable="false"
    :destroy-on-close="true"
    :z-index="9999"
    @close="onClose"
  >
    <TaskTitle icon-name="Det" title-name="线索详情" color="green" />
    <div class="list-container">
      <div class="progress-container">
        <TitleSecondary title="审批流程图" />
        <ProgressStaus />
      </div>
      <ProgressGraph :data="nodeFlowChartList" />
      <TitleSecondary title="基本信息" />
      <FormClueList :form="form" />
      <ProductList :data-source="detail.leadsProductList" />
      <ContactList :data-source="detail.leadsContactList" />
      <SalesTeamList :data-source="detail.leadsSalesTeamList" />
      <!-- <VisitList :data-source="detail.leadsVisitList" /> -->
      <AttachList :data-source="detail.attachmentList" />
      <ProgressLog :list="operationLogInformation" />
      <BottomLine />
    </div>
    <ButtonGroup
      class="footer"
      :options="footerButtons"
      @click="handleButtonClick"
    />
  </p-drawer>
</template>

<script>
import { getOperationLog, getProcessNode } from '@/api/clue.js';
import ProgressStaus from '@/components/task/ProgressStaus.vue';
import FormClueList from '@/components/task/FormClueList.vue';
import ProductList from '@/components/table/ProductList.vue';
import ContactList from '@/components/table/ContactList.vue';
import SalesTeamList from '@/components/table/SalesTeamList.vue';
// import VisitList from '@/components/table/VisitList.vue';
import AttachList from '@/components/table/AttachList.vue';
import ProgressGraph from '@/components/task/ProgressGraph.vue';
import ProgressLog from '@/components/task/ProgressLog.vue';
import DrawerMixin from './mixin';
export default {
  components: {
    ProgressStaus,
    FormClueList,
    ProductList,
    ContactList,
    SalesTeamList,
    // VisitList,
    AttachList,
    ProgressGraph,
    ProgressLog,
  },
  mixins: [DrawerMixin],
  data() {
    return {
      operationLogInformation: [], //操作日志请求返回的信息
      nodeFlowChartList: [],
    };
  },
  computed: {
    form() {
      return this.detail || {};
    },
    footerButtons() {
      return [
        {
          key: 'close',
          label: '返回',
        },
      ];
    },
  },
  watch: {
    visible: {
      handler(val) {
        val && this.handleChangeIcon();
        val && this.getProNode();
      },
      immediate: true,
    },
  },
  created() {
    console.log(this.$store.state.user.uid);
  },
  methods: {
    // 审批流程图
    async getProNode() {
      const res = await getProcessNode(this.processId, 'leads_create_node');
      this.nodeFlowChartList = res?.data?.data || [];
    },
    // 操作日志
    async handleChangeIcon() {
      const res = await getOperationLog('leads', this.detail.leadsNo);
      this.operationLogInformation = res.data.data;
    },
    onClose() {
      this.$emit('update:visible', false);
      this.$emit('fresh');
    },
    // 返回
    closeCallback() {
      this.onClose();
    },
    handleButtonClick(key) {
      const fn = `${key}Callback`;
      this[fn] && this[fn]();
    },
  },
};
</script>

<style lang="less" scoped>
.footer {
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-top: 1px solid #e5e6e9;
}
.list-container {
  height: calc(100vh - 110px);
  overflow-y: scroll;
  position: relative;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 10px 24px;
}

/deep/ .poros-drawer-body {
  min-width: 1136px;
  height: 100%;
  padding: 0;
}
.progress-container {
  width: 100%;
  display: flex;
  justify-content: space-between;
}
</style>
